package com.macrosolution.exdebito

import java.util.Date;
import java.util.List;

/**
 * Collaborator
 * A domain class describes the data object and it's mapping to the database
 */
class Customer implements Serializable{
	/* Default (injected) attributes of GORM */
	//	Long	id
	//	Long	version
		/* Automatic timestamping of GORM */
			
			Date	dateCreated
			Date	lastUpdated
			String name
			String surname
			String cf_piva
			String phone
			String mobile
			String email
			Date born
			Integer age
			Provincia bornProvince
			Comune bornMunicipality
			String nationality
			String citizen
			String sex
			int inItalyBy
			Address abode
			Address residence
			List families
//			refer to user
			Long 	userID
			List immobile
			List altroBene
			List debito
			Integer familiesNumber
			Job job
			List renditaTitDep 
			PersonaGiuridica personaGiuridica

			static hasMany = [families : Family, immobile : Immobile, altroBene : AltroBeneProp, debito : Debit, renditaTitDep : RenditaTitDep]

	//	static	belongsTo	= []	// tells GORM to cascade commands: e.g., delete this object if the "parent" is deleted.
	//	static	hasOne		= []	// tells GORM to associate another domain object as an owner in a 1-1 mapping
	//	static	hasMany		= []	// tells GORM to associate other domain objects for a 1-n or n-m mapping
	//	static	mappedBy	= []	// specifies which property should be used in a mapping
		
			static mapping = {
				abode cascade: 'all-delete-orphan'
				residence cascade: 'all-delete-orphan'
				families cascade: 'delete, all-delete-orphan'
				immobile cascade: 'delete, all-delete-orphan'
				altroBene cascade: 'delete, all-delete-orphan'
				debito cascade: 'delete, all-delete-orphan'
				job cascade: 'delete, all-delete-orphan'
				renditaTitDep cascade: 'delete, all-delete-orphan'
				personaGiuridica cascade: 'all-delete-orphan'
		   }
		
		static	constraints = {
				name nullable:true
				surname nullable:true
				cf_piva nullable:true
				phone nullable:true
				mobile nullable:true
				email nullable:true
				born nullable:true
				age nullable:true
				bornProvince nullable:true
				bornMunicipality nullable:true
				nationality nullable:true
				citizen nullable:true
				sex nullable:true
				inItalyBy nullable:true
				residence nullable:true
				families nullable:true
				userID nullable:true
				immobile nullable:true
				altroBene nullable:true
				debito nullable:true
				familiesNumber nullable:true
				job nullable:true
				renditaTitDep nullable:true
				abode nullable:true
				personaGiuridica nullable:true
			}


		@Override
		public String toString() {
			return this.name+" "+this.surname;
		}	
}
